package com.stu.testUser;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;

import com.stu.mapper.OrdersMapper;
import com.stu.mapper.UserMapper;
import com.stu.pojo.Order;
import com.stu.pojo.User;

public class UserTest2 {
	SqlSessionFactory sqlSessionFactory;
	@Before
	public void before() throws IOException {
		// 读取全局资源文件
		InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
		// 创建sqlsession
		sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
	}
	
	//根据订单编号查询用户信息
	@Test
	public void testUser() throws IOException {
		SqlSession sqlSession = sqlSessionFactory.openSession();
		OrdersMapper ordersMapper = sqlSession.getMapper(OrdersMapper.class);
		Order order = ordersMapper.findOrderUserByOnum(1000011);
		System.out.println(order);
		sqlSession.close();
	}
	
	//根据用户名查询用户的订单信息
	@Test
	public void testUser01() throws IOException {
		SqlSession sqlSession = sqlSessionFactory.openSession();
		UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
		User user = userMapper.findUserOrder("王五");
		System.out.println(user);
		sqlSession.close();
	}
	
	//根据用户名查询用户所购买的所有商品信息
	@Test
	public void testUser02() throws IOException {
		SqlSession sqlSession = sqlSessionFactory.openSession();
		OrdersMapper ordersMapper = sqlSession.getMapper(OrdersMapper.class);
		User user = ordersMapper.findOrdersPorduct("王五");
		System.out.println(user);
		sqlSession.close();
	}
}
